package com.xiaogao.serviceEdu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaogao.commonUtils.Result;
import com.xiaogao.serviceEdu.entity.EduCourse;
import com.xiaogao.serviceEdu.entity.EduTeacher;
import com.xiaogao.serviceEdu.service.EduCourseService;
import com.xiaogao.serviceEdu.service.EduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author 小高
 * @createtime 2021-06-30-9:47
 * @description
 */
@RestController
@RequestMapping("/serviceEdu/teacherFront")
@Api(description = "前台讲师管理页")
public class TeacherFrontController {

    @Autowired
    private EduTeacherService teacherService;

    @Autowired
    private EduCourseService courseService;

    @ApiOperation(value = "分页查询讲师")
    @GetMapping("/getTeacherFrontList/{page}/{limit}")
    public Result getTeacherFrontList(
            @ApiParam(name = "page",value = "当前页",required = true)
            @PathVariable("page")Long page,

            @ApiParam(name = "limit",value = "每页显示数",required = true)
            @PathVariable("limit")Long limit){

        Page<EduTeacher> pageTeacher = new Page<>(page,limit);
        Map<String,Object> map = teacherService.getPageList(pageTeacher);
        return Result.ok().data(map);
    }

    @ApiOperation(value = "查询讲师详情信息")
    @GetMapping("/getTeacherFrontInfo/{teacherId}")
    public Result getTeacherFrontInfo(
            @ApiParam(name = "teacherId",value = "讲师ID",required = true)
            @PathVariable("teacherId")String teacherId){
        // 根据讲师id查询讲师基本信息
        EduTeacher eduTeacher = teacherService.getById(teacherId);
        // 根据讲师id查询说有对应课程信息
        List<EduCourse> courseList = courseService.getByTeacherId(teacherId);
        return Result.ok().data("teacher",eduTeacher).data("courseList",courseList);
    }
}
